﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class UserControl_ucFindJob : System.Web.UI.UserControl
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
      
        if (!IsPostBack)
        {
            if (Session[Global.SESSION_LOGGED_USER] != null)
            {
               // int idCus = ((TblCustomers)Session[Global.SESSION_LOGGED_USER]).CustomerIndex;
                //loadJob(Convert.ToString(idCus));
            }
        }
    }

    public void loadJob(string id)
    {
        if (Session[Global.SESSION_LOGGED_USER] != null)
        {
            bool idAdmin = ((TblCustomers)Session[Global.SESSION_LOGGED_USER]).IsAdmin;
            if (((TblCustomers)Session[Global.SESSION_LOGGED_USER]) != null && idAdmin == false)
            {
                TblJobsDAO jobDAO = new TblJobsDAO(Global.CONNECTION_STRING);
                grdJobList.DataSource = jobDAO.GetJob(Global.ConvertToInt(id), ((TblCustomers)Session[Global.SESSION_LOGGED_USER]).Emailaddress);
                grdJobList.DataBind();
            }
            else if (((TblCustomers)Session[Global.SESSION_LOGGED_USER]) != null && idAdmin == true)
            {
                TblJobsDAO jobDAO = new TblJobsDAO(Global.CONNECTION_STRING);
                grdJobList.DataSource = jobDAO.GetJob(Global.ConvertToInt(id), "");
                grdJobList.DataBind();
            }
        }
    }
   
    protected void btnExt_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Default.aspx");
    }
    protected void grdJobList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Label lb_ApprovalStatus = (Label)e.Row.Cells[5].FindControl("lbApprovalStatus");
            //int AppStatus = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ApprovalStatus"));
            //if (AppStatus == 1)
            //    lb_ApprovalStatus.Text = " Approved ";
            //if(AppStatus == 0)
            //    lb_ApprovalStatus.Text = " Pending Approval";
            //if(AppStatus == 2)
            //    lb_ApprovalStatus.Text = " Quote Rejected ";

            //Label lb_QuotationStatus = (Label)e.Row.Cells[6].FindControl("lbQuotationStatus");
            //int QuotaStatus = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "QuotationStatus"));

            //if (QuotaStatus == 1)
            //    lb_QuotationStatus.Text = "Quoted";
            // if (QuotaStatus == 0)
            //    lb_QuotationStatus.Text = "Waiting for quote";
            //if(QuotaStatus == 2)
            //    lb_QuotationStatus.Text = "BER";
        }
    }

   
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        TblJobsDAO jobDAO = new TblJobsDAO(Global.CONNECTION_STRING);
        grdJobList.DataSource = jobDAO.GetJob(Global.ConvertToInt(txtJobID.Text), "");
        grdJobList.DataBind();
    }
}
